module.exports = app => {
    const seq = app.Sequelize;

    const User = app.model.define('user', {
        id:{
            type:seq.INTEGER,
            autoIncrement:true,
            allowNull:false,
            primaryKey:true,
            unique:true
        },
        openid:{
            type:seq.STRING,
            allowNull:false
        },
        subscribe: {
            type:seq.STRING,
            allowNull:true
        },
        nickname: {
            type:seq.STRING,
            allowNull:true,
        },
        sex:{
            type:seq.INTEGER,
            allowNull:true,
        },
        city:{
            type:seq.STRING,
            allowNull:true,
        },
        country:{
            type:seq.STRING,
            allowNull:true,
        },
        province:{
            type:seq.STRING,
            allowNull:true,
        },
        headimgurl:{
            type:seq.STRING,
            allowNull:true,
        },
        subscribeTime:{
            type:seq.STRING,
            allowNull:true,
        },
        remark:{
            type:seq.STRING,
            allowNull:true,
        },
        groupid:{
            type:seq.INTEGER,
            allowNull:true,
        },
        tagidList:{
            type:seq.INTEGER,
            allowNull:true,
        },
        token:{
            type:seq.STRING,
            allowNull:true,
        },
        status:{
            type:seq.INTEGER,
            allowNull:true,
        },
        sessionKey:{
            type:seq.STRING,
            allowNull:true,
        },
        expiresIn:{
            type:seq.DATE,
            allowNull:true,
        },
        isAdmin:{
            type:seq.INTEGER,
            allowNull:false,
            defaultValue:0
        }

    },{
        timestamps:true,
        paranoid:true,
        underscored:false
    });

    User.associate=function () {
        app.model.User.hasMany(app.model.ShopredRecord);
        app.model.User.hasMany(app.model.ShopredHistory);
        app.model.User.hasMany(app.model.Formmsg);
        app.model.User.hasMany(app.model.Score);
        app.model.User.hasMany(app.model.Nice);
        app.model.User.hasMany(app.model.ArticleComment);
        app.model.User.belongsTo(app.model.Wechat,{through:'wechat',foreignKey :'wechatId'});
    };


    return User;
};